package thead;

import java.util.concurrent.TimeUnit;

/**
 * @ProjectName: interview
 * @Package: thead
 * @ClassName: SimpleThread
 * @Author: chenmengqi
 * @Description:
 * @Date: 2020/4/1 2:38 下午
 * @Version: 1.0
 */
public class SimpleThread {
    public static void main(String[] args) {
        new Thread() {
            @Override
            public void run() {
                super.setName("news Thread");
                browseNews();
            }
        }.start();
        enjoyMusic();
    }

    private static void sleep(int seconds) {
        try {
            TimeUnit.SECONDS.sleep(seconds);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    /**
     * Browse the latest news.
     */
    private static void browseNews() {
        for (; ; ) {
            System.out.println("我在看新闻");
            sleep(1);
        }
    }

    /**
     * Listening and enjoy the music.
     */
    private static void enjoyMusic() {
        for (; ; ) {
            System.out.println("我在听音乐");
            sleep(1);
        }
    }
}
